package com.whmnx.chitchat.http;



import com.google.gson.internal.$Gson$Types;
import com.whmnx.chitchat.utils.UItils;
import com.whmnx.chitchat.view.CustomLoadingDialog;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import butterknife.internal.Utils;

/**
 *
 */
public abstract class CallBack<T> {
    public Type type;

    public CallBack() {
          type = getSuperclassTypeParameter(getClass());
    }

    static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }

    public abstract void onSuccess(T result);

    public void onFailure(int errorType, String message) {
        if (errorType == 4 ){
           // UItils.showToastSafe("服务器系统异常,请重新再试");
            CustomLoadingDialog.dismiss(UItils.getContext());
        }
    }
}

